package com.reggie.exception;

import com.reggie.common.ResultResponseVo;
import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author 早睡蛋
 * @Date 2022/7/25 10:15:01
 * @Desc:
 * 空白异常处理
 */
@Controller
public class UnifiedExceptionHandler extends AbstractErrorController {

    public UnifiedExceptionHandler(ErrorAttributes errorAttributes) {
        super(errorAttributes);
    }

    @RequestMapping("/error")
    @ResponseBody
    public ResultResponseVo error(HttpServletRequest request, HttpServletResponse response){
        response.setStatus(HttpStatus.OK.value());
        HttpStatus httpStatus = getStatus(request);
        ResultResponseVo resultResponseVo = ResultResponseVo.defaultFailResultResponse();
        return resultResponseVo;
    }

    @Override
    public String getErrorPath() {
        return "error";
    }
}
